import BaseController from "../../cfw/mvc/BaseController";
import ModuleManager, { ModuleID } from "../../cfw/module/ModuleManager";
import { UIIndex, ItemState } from "../../cfw/tools/Define";
import LobbyController from "../lobby/LobbyController";
import BadRoomManager from "./model/BadRoomManager";
import { ResultState } from "../../sdk/SDKConfig";
import SDKManager from "../../sdk/SDKManager";
import SleepToyItemModel from "./model/SleepToyItemModel";

const { ccclass, property } = cc._decorator;

@ccclass
export default class BadRoomController extends BaseController {

    private static ins: BadRoomController;



    static instance() {
        if (!this.ins) {
            this.ins = new BadRoomController()
        }
        return this.ins;
    }


    intoLayer() {
        ModuleManager.setModuleID(ModuleID.PUBLIC)
        this.pushView('prefabs/BadRoomView', 'BadRoomView', BadRoomManager.instance(), ModuleManager.getLoader(), UIIndex.ROOT)
    }

    back() {
        this.gotoLobby()
    }

    gotoLobby() {
        LobbyController.instance().intoLayer()
    }

    gotoNext() {
        this.gotoLobby()
    }



    openItem(model: SleepToyItemModel) {
        SDKManager.getChannel().showRewardAd(0, (state: ResultState) => {
            cc.log('showRewardAd  state == ', state)
            if (state == ResultState.YES) {
                model.setState(ItemState.GOT)
            }
        })
    }

    // update (dt) {}
}
